<?php
/**
 * Created by PhpStorm.
 * User: Dmitry
 * Date: 02.03.2015
 * Time: 16:07
 */

class AdminManager {

    private $currentSession;
    private $isAuthorize = false;
    private $admin = null;

    function __construct(&$session)
    {
        $this->currentSession = &$session;
        $this->isAuthorize = isset($this->currentSession->sessionData['admin']);
        if($this->isAuthorize)
            $this->admin = $this->currentSession->sessionData['admin'];
    }

    function login($username, $password)
    {
        $result = Context::DB()->queryAssoc("SELECT * FROM Admin WHERE Login = '$username' AND Password = '$password'");
        if($result != null)
        {
            $this->currentSession->sessionData['admin'] = array(
                "id" => $result[0]["Id"],
                "login" => $result[0]["Login"],
                "pass" => $result[0]["Password"]
            );
            $this->isAuthorize = true;
            return true;
        }
        return false;

    }

    function logout()
    {
        $this->currentSession->sessionData['admin'] = null;
        $this->isAuthorize = false;
    }

    function isAuthorize()
    {
        return $this->isAuthorize;
    }





}